home *** CD-ROM | disk | FTP | other *** search
/ Borland JBuilder 6 / jbuilder6.iso / Taiji Applet Pack v2.7 / TextEncrypter / TextEncrypter.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-11-06  |  6.3 KB  |  261 lines

  1. import java.applet.Applet;
  2. import java.awt.Button;
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Container;
  6. import java.awt.FlowLayout;
  7. import java.awt.FontMetrics;
  8. import java.awt.GridLayout;
  9. import java.awt.Label;
  10. import java.awt.Panel;
  11. import java.awt.TextArea;
  12. import java.awt.TextField;
  13. import java.awt.event.ActionEvent;
  14. import java.awt.event.ActionListener;
  15. import java.net.URL;
  16. import java.util.EventObject;
  17.  
  18. public class TextEncrypter extends Applet implements ActionListener {
  19.    // $FF: renamed from: wi int
  20.    private int field_0;
  21.    // $FF: renamed from: he int
  22.    private int field_1;
  23.    private boolean isFondhex = false;
  24.    private Color color;
  25.    private Color backColor;
  26.    // $FF: renamed from: fm java.awt.FontMetrics
  27.    private FontMetrics field_2;
  28.    // $FF: renamed from: p1 java.awt.Panel
  29.    private Panel field_3;
  30.    // $FF: renamed from: p2 java.awt.Panel
  31.    private Panel field_4;
  32.    // $FF: renamed from: p3 java.awt.Panel
  33.    private Panel field_5;
  34.    // $FF: renamed from: p4 java.awt.Panel
  35.    private Panel field_6;
  36.    private TextField key;
  37.    private TextArea ta1;
  38.    private TextArea ta2;
  39.    // $FF: renamed from: b1 java.awt.Button
  40.    private Button field_7;
  41.    // $FF: renamed from: b2 java.awt.Button
  42.    private Button field_8;
  43.    // $FF: renamed from: b3 java.awt.Button
  44.    private Button field_9;
  45.    private String text1;
  46.    private String text2;
  47.    private String text3;
  48.    private String text4;
  49.  
  50.    public String getAppletInfo() {
  51.       return "Name: TextEncrypter\r\nAuthor: Taiji Software\r\n";
  52.    }
  53.  
  54.    public void register() {
  55.       try {
  56.          URL u = new URL("http://www.taijisoftware.com");
  57.          ((Applet)this).getAppletContext().showDocument(u, "_blank");
  58.          ((Applet)this).stop();
  59.       } catch (Exception e) {
  60.          System.out.println(e);
  61.          ((Applet)this).stop();
  62.       }
  63.    }
  64.  
  65.    public void init() {
  66.       String codeBase = null;
  67.  
  68.       try {
  69.          codeBase = (new URL(((Applet)this).getCodeBase().toString())).getHost();
  70.          System.out.println("Copyright 1999, 2001 Taiji Software(tm)\nYour domain name is : " + codeBase);
  71.          codeBase = codeBase.toUpperCase();
  72.       } catch (Exception var9) {
  73.       }
  74.  
  75.       if (!((Applet)this).getCodeBase().toString().toUpperCase().startsWith("FILE") || ((Applet)this).getParameter("debug") != null) {
  76.          String regCode = ((Applet)this).getParameter("registration_code");
  77.          if (regCode == null) {
  78.             regCode = ((Applet)this).getParameter("reg_domain");
  79.             if (regCode == null) {
  80.                this.register();
  81.             } else {
  82.                if (regCode.length() == codeBase.length() + 4 && !codeBase.startsWith("WWW.")) {
  83.                   codeBase = "WWW." + codeBase;
  84.                } else if (regCode.length() == codeBase.length() - 4 && codeBase.startsWith("WWW.")) {
  85.                   codeBase = codeBase.substring(4);
  86.                }
  87.  
  88.                char[] chars = new char[codeBase.length()];
  89.                codeBase.getChars(0, codeBase.length(), chars, 0);
  90.                String key = new String("haricot");
  91.                char[] chars2 = new char[key.length()];
  92.                key.getChars(0, key.length(), chars2, 0);
  93.  
  94.                for(int i = 0; i < codeBase.length(); ++i) {
  95.                   int j;
  96.                   if (i >= key.length()) {
  97.                      j = i - key.length() * (i / key.length());
  98.                   } else {
  99.                      j = i;
  100.                   }
  101.  
  102.                   chars[i] += chars2[j];
  103.                   chars[i] = (char)(chars[i] - chars[i] / 26 * 26 + 97);
  104.                }
  105.  
  106.                String res = new String(chars);
  107.                if (!res.equalsIgnoreCase(regCode)) {
  108.                   this.register();
  109.                }
  110.             }
  111.          } else if (!regCode.equals("settevercsedegnamiaj") && !regCode.equals("8078")) {
  112.             this.register();
  113.          }
  114.       }
  115.  
  116.       this.getParameters();
  117.       ((Container)this).setLayout(new GridLayout(3, 1));
  118.       this.field_3 = new Panel();
  119.       this.field_4 = new Panel();
  120.       this.field_5 = new Panel();
  121.       ((Container)this).add(this.field_3);
  122.       ((Container)this).add(this.field_4);
  123.       ((Container)this).add(this.field_5);
  124.       this.field_3.setLayout(new GridLayout(3, 3));
  125.       this.field_4.setLayout(new GridLayout(1, 2));
  126.       this.field_5.setLayout(new GridLayout(3, 1));
  127.       this.field_3.add(new Label(this.text1));
  128.       this.key = new TextField();
  129.       this.field_3.add(this.key);
  130.       this.field_3.add(new Label(""));
  131.       this.field_3.add(new Label(""));
  132.       this.field_3.add(new Label(""));
  133.       this.field_3.add(new Label(""));
  134.       this.field_3.add(new Label(""));
  135.       this.field_3.add(new Label(""));
  136.       this.field_3.add(new Label(""));
  137.       this.ta1 = new TextArea("", 4, 30);
  138.       this.field_4.add(this.ta1);
  139.       this.ta2 = new TextArea("", 4, 30);
  140.       this.ta2.setEditable(false);
  141.       this.field_4.add(this.ta2);
  142.       this.field_7 = new Button(this.text2);
  143.       this.field_8 = new Button(this.text3);
  144.       this.field_9 = new Button(this.text4);
  145.       this.field_5.add(new Label(""));
  146.       Panel p32 = new Panel(new FlowLayout());
  147.       ((Container)p32).add(this.field_7);
  148.       ((Container)p32).add(this.field_8);
  149.       ((Container)p32).add(this.field_9);
  150.       this.field_5.add(p32);
  151.       this.field_7.addActionListener(this);
  152.       this.field_8.addActionListener(this);
  153.       this.field_9.addActionListener(this);
  154.       this.field_5.add(new Label(""));
  155.       this.key.setText("");
  156.       this.ta1.setText("");
  157.    }
  158.  
  159.    public void getParameters() {
  160.       this.field_0 = ((Component)this).getSize().width;
  161.       this.field_1 = ((Component)this).getSize().height;
  162.       this.text1 = ((Applet)this).getParameter("text1");
  163.       if (this.text1 == null) {
  164.          this.text1 = "Encrypt key: ";
  165.       }
  166.  
  167.       this.text2 = ((Applet)this).getParameter("text2");
  168.       if (this.text2 == null) {
  169.          this.text2 = "Encrypt !";
  170.       }
  171.  
  172.       this.text3 = ((Applet)this).getParameter("text3");
  173.       if (this.text3 == null) {
  174.          this.text3 = "Decrypt !";
  175.       }
  176.  
  177.       this.text4 = ((Applet)this).getParameter("text4");
  178.       if (this.text4 == null) {
  179.          this.text4 = "Clear";
  180.       }
  181.  
  182.       ((Component)this).setBackground(this.getColor("background_color"));
  183.    }
  184.  
  185.    public Color getColor(String param) {
  186.       String s = ((Applet)this).getParameter(param);
  187.       if (s != null) {
  188.          if (s.substring(0, 1).equals("#")) {
  189.             s = s.substring(1);
  190.             int i = Integer.parseInt(s, 16);
  191.             return new Color(i);
  192.          } else {
  193.             return null;
  194.          }
  195.       } else {
  196.          return null;
  197.       }
  198.    }
  199.  
  200.    public void actionPerformed(ActionEvent evt) {
  201.       if (((EventObject)evt).getSource() instanceof Button) {
  202.          String label = ((Button)((EventObject)evt).getSource()).getLabel();
  203.          System.out.println(label);
  204.          if (label.equals(this.text4)) {
  205.             this.ta1.setText("");
  206.             this.ta2.setText("");
  207.             return;
  208.          }
  209.  
  210.          String text = this.ta1.getText();
  211.          String keytext = this.key.getText();
  212.          System.out.println(keytext);
  213.          if (keytext.length() == 0) {
  214.             System.out.println("oui");
  215.             this.key.setText("Enter a key here !");
  216.             return;
  217.          }
  218.  
  219.          if (text.length() == 0) {
  220.             this.ta1.setText("Enter a text here !");
  221.             return;
  222.          }
  223.  
  224.          if (label.equals(this.text2)) {
  225.             this.ta2.setText(this.code(1, text, keytext));
  226.             return;
  227.          }
  228.  
  229.          if (label.equals(this.text3)) {
  230.             this.ta2.setText(this.code(-1, text, keytext));
  231.          }
  232.       }
  233.  
  234.    }
  235.  
  236.    public String code(int mode, String text, String key) {
  237.       char[] chars = new char[text.length()];
  238.       text.getChars(0, text.length(), chars, 0);
  239.       char[] chars2 = new char[key.length()];
  240.       key.getChars(0, key.length(), chars2, 0);
  241.  
  242.       for(int i = 0; i < text.length(); ++i) {
  243.          int j;
  244.          if (i >= key.length()) {
  245.             j = i - key.length() * (i / key.length());
  246.          } else {
  247.             j = i;
  248.          }
  249.  
  250.          int m = chars2[j] % 7;
  251.          if (chars2[2] >= 'P') {
  252.             chars[i] = (char)(chars[i] + mode * m);
  253.          } else {
  254.             chars[i] = (char)(chars[i] - mode * m);
  255.          }
  256.       }
  257.  
  258.       return new String(chars);
  259.    }
  260. }
  261.